<div id='billing_box'>
	<div class='title'><?php echo $this->__('Billing Address')?></div>
	<div class='content' >
		<p><?php echo $this->__('Please make sure the billing address you enter below matches the name and address associated with the credit card you are using for this purchase. Please note your billing address and shipping address country must be the same.')?></p>
		<div style="margin-bottom:8px;">
			<input checked="checked" type='radio' name='billing_address_id' value='<?php echo $this->getAddress()->getId()?>' />
			<label><?php echo $this->getAddress()->format('online')?></label>
			&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="javascript:void(0)" id="toEditAddr" style="display: inline; "><?php echo $this->__('Edit')?></a>
		</div>
		<form id='billing-form' action="<?php echo $this->getUrl('*/*/addressSave', array('_secure'=>true))?>" method='post' name='billing-form' style='display:none;'>
			<ul>
                <li class="fields"><?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getAddress())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?></li>
                <li class="fields">
                    <div class="field">
                        <label for="billing:company"><?php echo $this->__('Company') ?></label>
                        <div class="input-box">
                            <input type="text" id="billing:company" name="billing[company]" value="<?php echo $this->htmlEscape($this->getAddress()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="billing:email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
                        <div class="input-box">
                            <input type="text" name="billing[email]" id="billing:email" value="<?php echo $this->htmlEscape($this->getAddress()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
                        </div>
                    </div>
                </li>
                <li class="wide">
                    <label for="billing:street1" class="required"><em>*</em><?php echo $this->__('Address') ?></label>
                    <div class="input-box">
                        <input type="text" title="<?php echo $this->__('Street Address') ?>" name="billing[street][]" id="billing:street1" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet(1)) ?>" class="input-text required-entry" />
                    </div>
                </li>
        <?php for ($_i=2, $_n=$this->helper('customer/address')->getStreetLines(); $_i<=$_n; $_i++): ?>
                <li class="wide">
                    <div class="input-box" style="margin-top:14px;">
                        <input type="text" title="<?php echo $this->__('Street Address %s', $_i) ?>" name="billing[street][]" id="billing:street<?php echo $_i?>" value="<?php echo $this->htmlEscape($this->getAddress()->getStreet($_i)) ?>" class="input-text" />
                    </div>
                </li>
        <?php endfor ?>
                <li class="fields">
                    <div class="field">
                        <label for="billing:city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
                        <div class="input-box">
                            <input type="text" title="<?php echo $this->__('City') ?>" name="billing[city]" value="<?php echo $this->htmlEscape($this->getAddress()->getCity()) ?>" class="input-text required-entry" id="billing:city" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="billing:region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
                        <div class="input-box">
                            <select id="billing:region_id" name="billing[region_id]" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
                                <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                            </select>
                            <script type="text/javascript">
                            //<![CDATA[
                                $('billing:region_id').setAttribute('defaultValue',  "<?php echo $this->getAddress()->getRegionId() ?>");
                            //]]>
                            </script>
                            <input type="text" id="billing:region" name="billing[region]" value="<?php echo $this->htmlEscape($this->getAddress()->getRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
                        </div>
                    </div>
                </li>
                <li class="fields">
                    <div class="field">
                        <label for="billing:postcode" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
                        <div class="input-box">
                            <input type="text" title="<?php echo $this->__('Zip/Postal Code') ?>" name="billing[postcode]" id="billing:postcode" value="<?php echo $this->htmlEscape($this->getAddress()->getPostcode()) ?>" class="input-text validate-zip-international required-entry" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="billing:country_id" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
                        <div class="input-box">
                            <?php echo $this->getCountryHtmlSelect('billing') ?>
                        </div>
                    </div>
                </li>
                <li class="fields single">
                    <div class="field">
                        <label for="billing:telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
                        <div class="input-box">
                            <input type="text" name="billing[telephone]" value="<?php echo $this->htmlEscape($this->getAddress()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text required-entry" id="billing:telephone" />
                        </div>
                    </div>
               </li>
               <li class="fields single">
                    <div class="field">
                        <label for="billing:fax"><?php echo $this->__('Fax') ?></label>
                        <div class="input-box">
                            <input type="text" name="billing[fax]" value="<?php echo $this->htmlEscape($this->getAddress()->getFax()) ?>" title="<?php echo $this->__('Fax') ?>" class="input-text" id="billing:fax" />
                        </div>
                    </div>
                </li>
               <li class='operate'>
               <input type='hidden' name='address_id' value='<?php echo $this->getAddress()->getId()?>' />
               
               <button id="billing-save" type="submit" ><?php echo $this->__('Save')?></button>
			   <button id="cancel-billing" ><?php echo $this->__('Cancel')?></button>
							
               </li>
            </ul>
            <div class='clear'></div>
		</form>
	</div>
</div>
<script type="text/javascript">
//<![CDATA[
    var billingForm = new VarienForm('billing-form');
    var billingRegionUpdater = new RegionUpdater('billing:country_id', 'billing:region', 'billing:region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'billing:postcode');
//]]>
</script>
<script type="text/javascript">
jQuery.noConflict(); 
jQuery(document).ready(function($){
	$('#toEditAddr').click(function(){
		$('#billing-form').show();
		$(this).hide();
	});

	$('#cancel-billing').click(function(){
		$('#billing-form').hide();
		$('#toEditAddr').show();
		return false;//stop submit
	});

});
</script>
